package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.core.domain.AjaxResult;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.Taizhang004;
import com.aidex.biz.service.Taizhang004Service;
import org.springframework.web.multipart.MultipartFile;
import com.aidex.common.utils.SecurityUtils;

/**
 * 办公室处分执行Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/biz/bizTaizhang004")
public class Taizhang004Controller extends BaseController
{
    @Autowired
    private Taizhang004Service taizhang004Service;

    /**
     * 查询办公室处分执行列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:list')")
    @GetMapping("/list")
    public R<PageInfo> list(Taizhang004 taizhang004, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                taizhang004.setCompanyId(null);
        }else{
                     taizhang004.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        taizhang004.setPage(new PageDomain(request, response));
        return R.data(taizhang004Service.findPage(taizhang004));
    }

    /**
     * 获取办公室处分执行详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:query')")
    @GetMapping(value = "/{id}")
    public R<Taizhang004> detail(@PathVariable("id") String id)
    {
        return R.data(taizhang004Service.get(id));
    }

    /**
     * 新增办公室处分执行
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:add')")
    @Log(title = "办公室处分执行", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  Taizhang004 taizhang004)
    {
        return R.status(taizhang004Service.save(taizhang004));
    }

    /**
     * 修改办公室处分执行
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:edit')")
    @Log(title = "办公室处分执行", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated Taizhang004 taizhang004)
    {
        return R.status(taizhang004Service.save(taizhang004));
    }


    /**
     * 删除办公室处分执行
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:remove')")
    @Log(title = "办公室处分执行", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(taizhang004Service.deleteTaizhang004ByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(taizhang004Service.findMaxSort(new Taizhang004()));
    }

    /**
     * 导出办公室处分执行列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang004:export')")
    @Log(title = "办公室处分执行", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(Taizhang004 taizhang004)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    taizhang004.setCompanyId(null);
            }else{
                         taizhang004.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<Taizhang004> list = taizhang004Service.findList(taizhang004);
        ExcelUtil<Taizhang004> util = new ExcelUtil<Taizhang004>(Taizhang004.class);
        return util.exportExcel(list, "办公室处分执行数据");
    }

        @Log(title = "办公室处分执行导入", businessType = BusinessType.IMPORT)
        @PostMapping("/importData")
        public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
            ExcelUtil<Taizhang004> util = new ExcelUtil<Taizhang004>(Taizhang004.class);
            List<Taizhang004> taizhang004List = util.importExcel(file.getInputStream());
            String message = taizhang004Service.importData(taizhang004List);
            return AjaxResult.success(message);
        }


}
